package com.lagou;

import com.lagou.bean.ConsumerComponent;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.spring.context.annotation.EnableDubbo;
import org.springframework.context.annotation.*;
import org.springframework.stereotype.Component;

import java.io.IOException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @author: jie.zhao
 * @create: 2021/06/02 17:11
 */
@Component
public class AnnotationConsumerMain {

    public static void main(String[] args) throws IOException {
        AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(AnnotationConsumerMain.class);
        context.start();
        final ConsumerComponent consumerComponent = context.getBean(ConsumerComponent.class);
//        while (true) {
            System.in.read();
            String re = consumerComponent.sayHello("赵杰");
            System.out.println(re);
//        }

        ExecutorService executorService = Executors.newSingleThreadExecutor();
        for (int i = 0; i < 20000; i++) {
            executorService.submit(new Runnable() {
                public void run() {
                    consumerComponent.sayHello("赵杰");

                }
            });
            executorService.submit(new Runnable() {
                public void run() {
                    consumerComponent.methodTwo("赵杰");

                }
            });
            executorService.submit(new Runnable() {
                public void run() {
                    consumerComponent.methodThree("赵杰");

                }
            });
        }

    }


    @Configuration
    @EnableDubbo
    @ComponentScan("com.lagou.bean")
    @PropertySource("classpath:/dubbo-consumer.properties")
    static class ConsumerConfiguration {

        @Bean
        public RegistryConfig getRegistryConfig() {
            RegistryConfig registryConfig = new RegistryConfig();
            registryConfig.setAddress("zookeeper://localhost:2182");

            return registryConfig;
        }
    }
}
